﻿namespace PreGUI.Widgets
{
    using UnityEngine;
    using UnityEngine.UI;
    using PreGUI.Helpers;
    using PreGUI;

    /// <summary>
    /// PreGui Window Title
    /// </summary>
    public class PGWindowTitle : MonoBehaviour
    {
        public PreGui Gui { get; set; }
        public string Title;
        public GameObject TargetWindow;
    
        Image backgroundImage;
        LayoutElement layoutElement;
        Text titleCaption;

        void Start()
        {
            backgroundImage = gameObject.AddComponent<Image>();
            backgroundImage.color = Gui.TitleBarSettings.BarColor;
            backgroundImage.sprite = Gui.ControlSprite;
            backgroundImage.type = Image.Type.Sliced;

            layoutElement = gameObject.AddComponent<LayoutElement>();
            layoutElement.minHeight = 26f;

            var titleGameObject = new GameObject("Title");
            titleGameObject.transform.SetParent(this.gameObject.transform, false);
            titleGameObject.AddComponent<PGDraggable>().Target = TargetWindow;
            titleCaption = titleGameObject.AddComponent<Text>();
            titleCaption.font = Gui.TitleBarSettings.Font;
            titleCaption.fontStyle = Gui.TitleBarSettings.FontStyle;
            titleCaption.fontSize = Gui.TitleBarSettings.FontSize;
            titleCaption.text = Title;
            titleCaption.alignment = TextAnchor.MiddleCenter;

        }


    }
}

